In this part, we will learn how to create a simple Java program. After installing the JDK,
we can simply construct a basic hello Java application.
To write a simple Java program, you must first create a class that has the main function.
First, let us clarify the prerequisite.
To run Java programs, you must have the following software or applications properly installed:
Let's have a quick look at Simple Java hello world program example
/* This is first java program
This will print 'Hello Alok'
as the output */
class Simple{
public static void main(String args[ ]){
System.out.println("Hello Alok" );
}
}
Output:
Hello Alok
In the above Java program you have use following keyword
Till now,We have learnt how to compile and run a java programme, as well as about the first java programme.
Here, we'll discover what occurs when Java applications are compiled and executed.
At compile time, java file is compiled by java compiler and converts the java code or source code into bytecode i.e .class file
/* This is my first java program
This will print 'Hello World!'
as the output */
class Simple{
public static void main(String args[ ]){
System.out.println("Hello World!" );
}
}
Output:
Hello World!
At the run time following steps are performed:
Bytecode in java is just a symbol and each symbol taking one byte in memory that is the reason is called bytecode. Bytecode i.e .class file is generated by the java compiler and after compilation of java source code bytecode is generated, now these bytecode are loaded into java virtual machine(JVM) and then interpreted and then execute. Java programming language is WORA(Write Once Run Anywhere) programming language i.e it is reusable and it save time too.
java file(source file)→compiler→.class file(bytecode)→machine code
Post your comment